/**
 *
 */
package org.insia.smartposse.manager;

import org.insia.smartposse.manager.iface.IManager;
import org.insia.smartposse.mapping.Skills;
import org.insia.smartposse.mapping.dao.SkillsDAO;

/**
 * @author cmougel
 *
 */
public class SkillManager implements IManager {

	private final Skills _skill;
	private final SkillsDAO _dao = new SkillsDAO();

	public SkillManager(){
		_skill = new Skills();
	}

	/**
	 * Constructor this already a Skill
	 *
	 * @param skill
	 */
	public SkillManager(Skills skill) {
		_skill = skill;
	}

	/**
	 * Load a Skill with his Id
	 *
	 * @param id
	 */
	public SkillManager(int id) {
		_skill = _dao.load(id, _dao.getSession());
	}

	/* (non-Javadoc)
	 * @see org.insia.smartposse.manager.iface.IManager#save()
	 */
	public void save() {

		// No NULL in database
		if (null == _skill.getName()){
			_skill.setName("");
		}

		_dao.saveOrUpdate(_skill);

	}

	/**
	 * Define the Name of This Skill
	 *
	 * @param name
	 */
	public void setName(String name) {
		_skill.setName(name);

	}

	/**
	 * @return The name of this Skill
	 */
	public String getName(){
		return _skill.getName();
	}

	/**
	 *
	 * @return the skill save into this SkillManager
	 */
	public Skills getSkill() {
		return _skill;
	}

	public Integer getId() {
		return _skill.getId();
	}

}
